package cn.hchaojie.camp.day04;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class DemoTimo {
	public int findPoisonedDuration(int[] timeSeries, int duration) {
		if (timeSeries.length == 0) {
			return 0;
		}
		
		int sum = 0;
		for (int i = 0; i < timeSeries.length - 1; i++) {
			if (timeSeries[i] + duration - 1 >= timeSeries[i + 1]) {
				sum += timeSeries[i + 1] - timeSeries[i];
			} else {
				sum += duration;
			}
		}
		sum += duration;

		return sum;
	}
	
	@Test
	public void test1() {
		assertTrue(findPoisonedDuration(new int[] {1, 4}, 2) == 4);
		assertTrue(findPoisonedDuration(new int[] {1, 2}, 2) == 3);
	}
}
